package course.d1222;
/*
自定义编译器异常：
格式： 修饰符 class XxxException extends Exception{
  public XxxException (String message){
           super(message);
           }
           public XxxException(){
          }
     }
     使用throw主动抛出一个异常对象；
     格式：  throw  异常对象

     自定义一个运行期异常
     格式： 修饰符 class XxxException extends RuntimeException{
           public XxxException (String message){
            super(message);
            }
            public XxxException() {

    }

 */
public class p7 {
    public static void main(String[] args) {
        try {
            login("admin","15166");
        } catch (loginException e) {
            System.out.println(e);
        }
        System.out.println("=================");
        try{
            get("单身");
        }catch (Exception e){
            System.out.println(e);
        }

        System.out.println("运行结束");
    }
    public static void  login(String name,String password) throws loginException {
        if ("admin".equals(name)&&"123456".equals(password)){
            System.out.println("登陆成功");
        }else {
            throw new loginException("用户名或者密码错误");
        }
    }

    public static void get(String m){
        if ("单身".equals(m)){
            throw new NotFoundGirlFriendException("单身异常");
        }else {
            System.out.println("好好恋爱");
        }
        System.out.println("get结束");
    }
}
class loginException extends Exception{
    public loginException() {
    }
    public loginException(String s) {
        super(s);
    }
}
class NotFoundGirlFriendException extends  RuntimeException{
    public NotFoundGirlFriendException() {
    }

    public NotFoundGirlFriendException(String s) {
        super(s);
    }
}
